package com.yun.blog.controller;

import com.yun.blog.bean.Result;
import com.yun.blog.service.BlogService;
import com.yun.blog.service.CategoryService;
import com.yun.blog.service.TagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * title        : DataAnalysisController
 * projectName  : dantouBlog-back
 * description  : TODO
 * author       : simple
 * date         : 2022/12/8上午11:00
 */

@Slf4j
@RestController
@RequestMapping("/data")
public class DataAnalysisController {

    @Resource
    BlogService blogService;

    @Resource
    TagService tagService;

    @Resource
    CategoryService categoryService;

    /**
     * 首页得到博客，分类，标签的数量
     *
     * @return java.lang.Integer
     **/
    @GetMapping("/indexGetCount")
    public Result getCount() {
        try {
            Result success = Result.success("success");
            success.add("blogCount", blogService.count());
            success.add("tagCount", tagService.count());
            success.add("categoryCount", categoryService.count());
            return success;
        } catch (Exception e) {
            log.error("获取数量失败：错误信息为：{}", e.getMessage());
            return Result.fail("获取数量失败：错误信息为：" + e.getMessage());
        }
    }

}
